"""
    Author:
    Date: 2019-12-04

    用户注册管理类
"""

from utils import db

def is_registered_mobile(mobile):
    """ 判断是否是注册过的手机号码 """
    sql = '''
        SELECT      id
        FROM        cmf_users_registration
        WHERE       mobile=%(mobile)s
        LIMIT       1;
    '''
    params = {
        'mobile': mobile,
    }
    data = db.query_data_from_db(sql, params)
    return data is not None and len(data) == 1


def register_mobile(mobile, app, channel, ip):
    """ 注册手机号 """
    sql = '''
        INSERT INTO cmf_users_registration
        SET         mobile=%(mobile)s,
                    app=%(app)s,
                    channel=%(channel)s,
                    ip=%(ip)s;
    '''
    params = {
        'mobile': mobile,
        'app': app,
        'channel': channel,
        'ip': ip,
    }
    affected = db.execute_sql(sql, params)
    return affected == 1


if __name__ == '__main__':
    print('ok')

